package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    @PostMapping
    public Result addDish(@RequestBody DishDTO dishDTO){
            log.info("新增菜品内容：{}", dishDTO);
            dishService.addDish(dishDTO);
            return Result.success();
    }

    @GetMapping("/page")
    public Result page(DishPageQueryDTO pageQueryDTO){
        log.info("菜品分页查询：{}", pageQueryDTO);
        PageResult pageResult = dishService.page(pageQueryDTO);
        return Result.success(pageResult);
    }



    //删除菜品
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("批量删除菜品，ids：{}", ids);
        dishService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<DishVO> getInfo(@PathVariable Long id){
        log.info("查询菜品信息 id：{}", id);
        DishVO dishVO = dishService.getInfo(id);
        return Result.success(dishVO);
    }

    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("修改菜品内容：{}", dishDTO);
        dishService.update(dishDTO);
        return Result.success();
    }

    @PutMapping("/status/{status}/{id}")
    public Result startOrStop(@PathVariable Integer status, @PathVariable Long id){
        log.info("修改菜品状态：{}", status);
        dishService.startOrStop(status, id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Dish>> list(Long categoryId, String name){
        log.info("查询分类下的菜品：{}", categoryId);
        List<Dish> list = dishService.list(categoryId, name);
        return Result.success(list);
    }

}
